﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace Fares
{
    public partial class OptiuniRapoarteFrm : FrmCard
    {
        public int LunaCurenta = 0;
        public int AnulCurent = 0;
        private String SerieNumerica = string.Empty;
        private Int16 tipRaport = 0;
        private Boolean ParteneriProprii = true;
        private Boolean FolosesteDataExtras = false;

        public OptiuniRapoarteFrm(ModuleClass mc,Int16 _tiprap):
            base(mc)
        {
            tipRaport = _tiprap;
            InitializeComponent();
            workConnString = mc.workConnectionString;
            denumireContCB.Visible = false;
            switch(tipRaport)
            {
                case 1:
                    Text = "Optiuni rapoarte - Categorii articole";
                    break;
                case 2:
                    Text = "Optiuni rapoarte - Liste documente";
                    DefalcatTVACB.Visible = true;
                    break;
                case 3:
                    Text = "Optiuni rapoarte - Operatiuni Contabile";
                    denumireContCB.Visible = true;
                    break;
                case 4:
                    Text = "Optiuni rapoarte - Facturi";
                    documenteCLB.Visible = false;
                    DocumenteL.Visible = false;
                    LiniidetaliateTVACB.Visible = true;
                    break;
                case 5:
                    Text = "Optiuni rapoarte - Operatiuni incasare/plata";
                    TVARB.Visible = false;
                    dimensiuneRB.Visible = false;

                    break;
                case 6:
                    Text = "Optiuni rapoarte - Fisa partenerului";
                    DateL.Text = "La data:";
                    DeLaDTP.Visible = false;
                    GrupareGB.Visible = false;
                    FisaParteneruluiGB.Visible = true;
                    break;

                default:
                    Text = "Optiuni rapoarte";
                    break;
            }
            PanaLaDTP.Format = DateTimePickerFormat.Custom;
            PanaLaDTP.CustomFormat = "dd.MM.yyyy";
            DeLaDTP.Format = DateTimePickerFormat.Custom;
            DeLaDTP.CustomFormat = "dd.MM.yyyy";

            panalaPDTP.Format = DateTimePickerFormat.Custom;
            panalaPDTP.CustomFormat = "dd.MM.yyyy";
            delaPDTP.Format = DateTimePickerFormat.Custom;
            delaPDTP.CustomFormat = "dd.MM.yyyy";
            soldDTP.Format = DateTimePickerFormat.Custom;
            soldDTP.CustomFormat = "dd.MM.yyyy";


            PanaLaDataReceptieDTP.Format = DateTimePickerFormat.Custom;
            PanaLaDataReceptieDTP.CustomFormat = "dd.MM.yyyy";
            DeLaDataReceptieDTP.Format = DateTimePickerFormat.Custom;
            DeLaDataReceptieDTP.CustomFormat = "dd.MM.yyyy";


        }

        private void OptiuniRapoarteFrm_Load(object sender, EventArgs e)
        {         
            SqlConnection con = DeschideConexiune(workConnString);

            #region Determinare luna,an curent
            Object ret = GetSetupValue("FaresSetup", "IDSerie", ModuleInfo.CodUnitate, con);
            String val = String.Empty;
            if (ret != null && ret != DBNull.Value)
                val = ret.ToString();
            else
            {
                while (ret == null)
                {
                    MessageBox.Show("Modulul Parteneri nu a fost configurat. \nVa rugam sa-l configurati!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                    FaresSetupFrm frm = new FaresSetupFrm(this.ModuleInfo);
                    frm.ShowDialog();
                    ret = GetSetupValue("FaresSetup", "IDSerie", ModuleInfo.CodUnitate, con);
                }
            }
            SerieNumerica = val;
            Object retObj = GetSetupValue("FaresSetup", "LunaCurenta", ModuleInfo.CodUnitate, con);
            if (retObj != null && retObj != DBNull.Value)
                LunaCurenta = Convert.ToInt32(retObj);
            retObj = GetSetupValue("FaresSetup", "AnCurent", ModuleInfo.CodUnitate, con);
            if (retObj != null && retObj != DBNull.Value)
                AnulCurent = Convert.ToInt32(retObj);

            retObj = GetSetupValue("FaresSetup", "ParteneriProprii", ModuleInfo.CodUnitate, con);
            if (retObj != null && retObj != DBNull.Value)
                ParteneriProprii = Convert.ToBoolean(retObj);

            retObj = GetSetupValue("FaresSetup", "FolosesteDataExtras", ModuleInfo.CodUnitate, con);
            if (retObj != null && retObj != DBNull.Value)
                FolosesteDataExtras = Convert.ToBoolean(retObj);

            #endregion

            DateTime inceputLuna = new DateTime(AnulCurent, LunaCurenta, 1);
            DateTime sfarsitLuna = inceputLuna.AddMonths(1).AddDays(-1);
            DeLaDTP.Value = inceputLuna;
            PanaLaDTP.Value = sfarsitLuna;
            delaPDTP.Value = inceputLuna;
            panalaPDTP.Value = sfarsitLuna;
            DeLaDataReceptieDTP.Value = inceputLuna;
            PanaLaDataReceptieDTP.Value = sfarsitLuna;
            switch (tipRaport)
            {
                case 1:
                    platiTC.Visible = false;
                    
                    break;
                case 2:
                    platiTC.TabPages.Remove(platiTP);
                    platiTC.TabPages.Remove(facturiTP);
                    break;
                case 3:
                    platiTC.TabPages.Remove(platiTP);
                    platiTC.TabPages.Remove(facturiTP);
                    platiTC.TabPages.Remove(receptiiTP);
                    break;
                case 4: //facturi
                    platiTC.TabPages.Remove(receptiiTP);
                    //platiTC.TabPages.Remove(documenteTP);
                    platiTC.TabPages.Remove(platiTP);
                    articoleGB.Visible = false;
                    break;
                case 5: //facturi
                    platiTC.TabPages.Remove(receptiiTP);
                    platiTC.TabPages.Remove(facturiTP);
                    articoleGB.Visible = false;
                    break;
                case 6: //fisa partenerului
                    platiTC.TabPages.Remove(receptiiTP);
                    platiTC.TabPages.Remove(facturiTP);
                    platiTC.TabPages.Remove(platiTP);
                    articoleGB.Visible = false;
                    break;

                default:
                    platiTC.TabPages.Remove(receptiiTP);
                    break;
            }
            try
            {
                this.articoleTableAdapter.Connection = con;

                this.balconSetupTableAdapter.Connection = con;
                this.balconSetupTableAdapter.FillByUnitate(this.eSRPDataSetListe.BalconSetup, ModuleInfo.CodUnitate);

                this.articoleTableAdapter.Fill(this.eSRPDataSetListe.Articole, ModuleInfo.CodUnitate);
                this.fares_ParteneriCUITableAdapter.Connection = con;
                if (ParteneriProprii)
                    this.fares_ParteneriCUITableAdapter.FillByUnitate(this.eSRPDataSetListe.fares_ParteneriCUI, ModuleInfo.CodUnitate);
                else
                    this.fares_ParteneriCUITableAdapter.Fill(this.eSRPDataSetListe.fares_ParteneriCUI);
            }
            catch (Exception ex)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare", ex.Message, String.Empty,MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Iesire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
            }

            AddButton("Genereaza[F9]", global::ERPStudio.Properties.Resources._001_07, Genereaza, ToolStripItemAlignment.Right, false);

            SqlCommand cmd = new SqlCommand("SELECT * FROM admin_DocumenteDisponibile WHERE [ApplicationID]='892862E5-637B-4BBC-AE2B-2DAC0FFD3DF9'", DeschideConexiune("ESRPConnectionString"));
            if (tipRaport == 5)
            {
                cmd.CommandText = "Select * FROM [TipDocumentPlata]";
            }
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                
                if (tipRaport == 5)
                    this.tipuriCLB.Items.Add(new _itemInfo(dr["Denumire"].ToString() , Convert.ToInt32(dr["IDTipPlata"])), true);
                else
                    this.tipuriCLB.Items.Add(new _itemInfo(dr["Denumire"] + "(" + dr["TipOperatie"] + ")", dr["TipOperatie"].ToString(), Convert.ToInt32(dr["IDTipDocument"])), true);

            }
            dr.Close();
            //adauga si platile
            if (tipRaport == 6)
            {
                cmd.CommandText = "Select * FROM [TipDocumentPlata]";
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.tipuriCLB.Items.Add(new _itemInfo(dr["Denumire"].ToString(),1000+ Convert.ToInt32(dr["IDTipPlata"])), true);
                }
                dr.Close();
            }


            this.documenteCLB.Items.Add(new _itemInfo("Intrate","I"), true);
            this.documenteCLB.Items.Add(new _itemInfo("Iesite", "O"), true);
            HandleSalvare += Genereaza;
            InchideConexiune(con);
        }

        private void Genereaza(object sender, EventArgs e)
        {

            String filtruArt = string.Empty;
            String filtruPart = string.Empty;
            String filtruCat = string.Empty;
            String filtruTip = string.Empty;

            String filtru = " [CodUnitate] = " + ModuleInfo.CodUnitate.ToString();
            String NumeRaport = "Documente.rdlc";

            switch(tipRaport)
            {
                case 1:
                    NumeRaport = "CentralizatorCategoriiArticole.rdlc";
                    break;
                case 2:
                    NumeRaport = "DocumenteReceptii.rdlc";
                    if (platiTC.SelectedTab == receptiiTP)
                    { 
                        //selectate receptiile
                        if (marfuriRB.Checked)
                        {
                            NumeRaport = "DocumenteMarfa.rdlc";
                            if (DefalcatTVACB.Checked)
                            {
                                NumeRaport = "DocumenteMarfaTVA.rdlc";
                            }
                        }
                    }
                    if (platiTC.SelectedTab == documenteTP)
                    {
                        NumeRaport = "Documente.rdlc";
                    }

                    break;
                case 3:
                    NumeRaport = "OperatiuniConturi.rdlc";
                    break;
                case 4:
                    NumeRaport = "Facturi.rdlc";
                    if (LiniidetaliateTVACB.Checked)
                    {
                        NumeRaport = "FacturiDetaliate.rdlc";
                    }
                    break;
                case 5:
                    NumeRaport = "Plati.rdlc";
                    break;
                case 6:
                    NumeRaport = "FisaPartenerului.rdlc";
                    break;
                default:
                    return;

            }

            if (partenerRB.Checked)
            {
                if (partenerCB.SelectedValue != null)
                    filtruPart = partenerCB.SelectedValue.ToString();
            }
            else
                if (parteneriRB.Checked)
                {
                    for (Int16 i = 0; i < articoleSelectateBindingSource.Count; i++)
                    {
                        if (filtruPart != String.Empty)
                            filtruPart += ",";
                        filtruPart += ((FurnizoriArticoleSelectate)furnizoriSelectatiBindingSource.List[i]).Tag.ToString();
                    }
                }

            if (articoleGB.Visible && articolRB.Checked)
            {
                filtruArt = articolCB.SelectedValue.ToString();
            }
            if (articoleGB.Visible && articoleRB.Checked)
            {
                for (Int16 i = 0; i < articoleSelectateBindingSource.Count; i++)
                {
                    if (filtruArt != String.Empty)
                        filtruArt += ",";
                    filtruArt += ((FurnizoriArticoleSelectate)articoleSelectateBindingSource.List[i]).Tag.ToString();
                }
            }
            
            int cate = 0;
            foreach (_itemInfo ci in tipuriCLB.CheckedItems)
            {
                if (filtruTip != String.Empty)
                    filtruTip += ",";
                filtruTip += ci.Cod.ToString();
                cate++;
            }



            PreviewRaportFrm frm = new PreviewRaportFrm(NumeRaport, null, ModuleInfo);

            SqlConnection con=DeschideConexiune(workConnString);
            switch (tipRaport)
            {
                case 4:
                    frm.dataloadHandler += new LoadDataHandler(frm_dataloadHandler);
                    break;
                default:
                    break;
            }

  

            try{

            switch (tipRaport)
            {
                case 1:
                        eSRPDataSetListe.EnforceConstraints = false;
                        this.fares_FiltreazaRaportArticoleComandaTableAdapter.Connection = con;
                        this.fares_FiltreazaRaportArticoleComandaTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportArticoleComanda,
                            filtruPart, filtruArt, DeLaDTP.Value, PanaLaDTP.Value, ModuleInfo.CodUnitate);
                        frm.AddDataSource("fares_FiltreazaRaportArticoleComanda", fares_FiltreazaRaportArticoleComandaBindingSource);
                    break;
                case 2:
                    if (marfuriRB.Checked && DefalcatTVACB.Checked)
                    {
                        this.fares_FiltreazaRaportDocumenteTVATableAdapter.Connection = con;
                        this.fares_FiltreazaRaportDocumenteTVATableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportDocumenteTVA,
                                filtruPart, filtruArt,filtruTip, DeLaDTP.Value, PanaLaDTP.Value, DefalcatTVACB.Checked, platiTC.SelectedTab == receptiiTP,
                                ModuleInfo.CodUnitate,
                                DeLaDataReceptieDTP.Value,PanaLaDataReceptieDTP.Value);
                        frm.AddDataSource("fares_DocumenteDimensiuni", fares_FiltreazaRaportDocumenteTVABindingSource);
                    }
                    else
                    {
                        this.fares_FiltreazaRaportDocumenteTableAdapter.Connection = con;
                        this.fares_FiltreazaRaportDocumenteTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportDocumente,
                                filtruPart, filtruArt,filtruTip, DeLaDTP.Value, PanaLaDTP.Value, DefalcatTVACB.Checked, platiTC.SelectedTab == receptiiTP,
                                marfuriRB.Checked,ModuleInfo.CodUnitate);
                        frm.AddDataSource("fares_DocumenteDimensiuni", fares_FiltreazaRaportDocumenteBindingSource);
                    }
                    break;
                case 3:
                    this.fares_FiltreazaRaportOpConturiTableAdapter.Connection = con;
                    this.fares_FiltreazaRaportOpConturiTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportOpConturi,
                                filtruPart, filtruArt,filtruTip, DeLaDTP.Value, PanaLaDTP.Value, 
                                ModuleInfo.CodUnitate);
                    frm.AddDataSource("fares_DocumenteDimConturi", fares_FiltreazaRaportOpConturiBindingSource);
                    break;
                case 4:
                    eSRPDataSetListe.EnforceConstraints = false;
                    this.fares_FiltreazaRaportFacturiTableAdapter.Connection = con;
                    this.fares_FiltreazaRaportFacturiTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportFacturi,
                        filtruPart, filtruTip, DeLaDTP.Value, PanaLaDTP.Value,soldDTP.Value,facturiSoldCB.Checked,totalNeachitateCB.Checked,integralAchitateCB.Checked,
                                ModuleInfo.CodUnitate);                     
                    frm.AddDataSource("fares_Facturi", fares_FiltreazaRaportFacturiBindingSource);
                    break;
                case 5:
                    eSRPDataSetListe.EnforceConstraints = false;
                    short docCLB = 0;
                    if (documenteCLB.CheckedIndices[0] == 1)
                            docCLB=1;
                    this.fares_FiltreazaRaportPlatiTableAdapter.Connection = con;
                    this.fares_FiltreazaRaportPlatiTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportPlati,
                        filtruPart,filtruTip, DeLaDTP.Value, PanaLaDTP.Value, numaiAvansuriCB.Checked, docCLB,perioadaFacturaCB.Checked,delaPDTP.Value,panalaPDTP.Value,
                                ModuleInfo.CodUnitate);
                    frm.AddDataSource("fares_Plati", fares_FiltreazaRaportPlatiBindingSource);
                    break;
                case 6:
                    this.fares_FiltreazaRaportFisaParteneruluiTableAdapter.Connection = con;
                    this.fares_FiltreazaRaportFisaParteneruluiTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportFisaPartenerului,
                        filtruPart,filtruTip,PanaLaDTP.Value,
                                ModuleInfo.CodUnitate);

                    frm.AddDataSource("fares_FisaPartenerului", fares_FiltreazaRaportFisaParteneruluiBindingSource);
                    if (CronologicRB.Checked)
                    {
                        fares_FiltreazaRaportFisaParteneruluiBindingSource.Sort = "DataDoc,IDTipDocument";
                    }
                    if (SeparatIORB.Checked)
                    {
                        fares_FiltreazaRaportFisaParteneruluiBindingSource.Sort = "IDTipDocument,DataDoc";
                    }

                    break;
                default:
                        this.fares_FiltreazaRaportDocumenteTableAdapter.Connection = con;
                        this.fares_FiltreazaRaportDocumenteTableAdapter.Fill(this.eSRPDataSetListe.fares_FiltreazaRaportDocumente,
                              filtruPart, filtruArt,filtruTip, DeLaDTP.Value, PanaLaDTP.Value, DefalcatTVACB.Checked, platiTC.SelectedTab == receptiiTP,
                             marfuriRB.Checked,ModuleInfo.CodUnitate);
                        frm.AddDataSource("fares_DocumenteDimensiuni", fares_FiltreazaRaportDocumenteBindingSource);
                    break;
            
            }

        }

        catch (System.Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
        }

            Int16 grupare = 0;
            if (DataRB.Checked)
                grupare = 1;
            else
                if (TVARB.Checked)
                    grupare = 2;
                else
                    if (grupPartenerRB.Checked)
                        grupare = 3;
                    else
                        if (dimensiuneRB.Checked)
                            grupare = 4;
            frm.AddDataSource("BalconSetup", balconSetupBindingSource);
            switch (tipRaport)
            {
                case 1:
                    frm.AddParameter("Linia1", "Lista documentelor", true);
                    break;
                case 2:
                    if (platiTC.SelectedTab == receptiiTP)
                    {
                        if (consumRB.Checked)
                            frm.AddParameter("Linia1", "Lista receptiilor pentru consum intern", true);
                        if (marfuriRB.Checked)
                        {
                            frm.AddParameter("Linia1", "Lista receptiilor pentru marfa", true);
                        }
                    }
                    else
                    {
                        frm.AddParameter("Linia1", "Lista documentelor", true);
                    }
                    
                    break;
                case 3:
                    frm.AddParameter("Linia1", "Lista operatiunilor pe conturi", true);
                    frm.AddParameter("denumireCont", denumireContCB.Checked?"True":"False", true);
                    break;
                case 4:
                    frm.AddParameter("Linia1", "Lista facturilor", true);
                    frm.AddParameter("documenteplata", documenteplataCB.Checked? "True":"False", true);
                    frm.AddParameter("FolosesteDataExtras", FolosesteDataExtras ? "True" : "False", true);
                    break;
                case 5:
                    frm.AddParameter("Linia1", "Lista operatiuni de plata", true);
                    frm.AddParameter("FolosesteDataExtras", FolosesteDataExtras ? "True" : "False", true);
                    break;
                case 6:
                    frm.AddParameter("Linia1", "Fisa partenerului", true);
                    frm.AddParameter("FolosesteDataExtras", FolosesteDataExtras ? "True" : "False", true);
                    break;
                default:
                    return;

            }

            switch (tipRaport)
            {
                case 6:
                    frm.AddParameter("Linia2", "La data: "+ PanaLaDTP.Value.Day.ToString() + "." + PanaLaDTP.Value.Month.ToString() + "." + PanaLaDTP.Value.Year.ToString(), true);
                    break;
                default:
                    frm.AddParameter("Linia2", "Pentru perioada " + DeLaDTP.Value.Day.ToString() + "." + DeLaDTP.Value.Month.ToString() + "." + DeLaDTP.Value.Year.ToString() + "-" +
                PanaLaDTP.Value.Day.ToString() + "." + PanaLaDTP.Value.Month.ToString() + "." + PanaLaDTP.Value.Year.ToString(), true);
                    break;

            }
            


            frm.AddParameter("detaliata", detaliataCB.Checked?"True":"False", true);
            if (tipRaport!=1)
                frm.AddParameter("grupare", grupare.ToString(), true);
            
            frm.MdiParent = MdiParent;
            
            frm.renderCompleteHandler += new RenderingComplete(frm_renderCompleteHandler);
            frm.Show();
            InchideConexiune(con);
        
        }

        void frm_renderCompleteHandler(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)
        {
            if (sqlConnSubrep != null)
            {
                InchideConexiune(sqlConnSubrep);
                sqlConnSubrep = null;
            }
           
        }

        private SqlConnection sqlConnSubrep = null;
        void frm_dataloadHandler(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs args)
        {
            DataSets.ESRPDataSetListe eSRPDS = new DataSets.ESRPDataSetListe();
            BindingSource bs = null;
            SqlDataAdapter ta = null;
            if (sqlConnSubrep==null)
                sqlConnSubrep = DeschideConexiune(workConnString);

            if (args.ReportPath == "PlatiFacturiSubreport" )
            {
                Int64 iddocument = Convert.ToInt64(args.Parameters["identDocument"].Values[0]);
                
                bs = new BindingSource(eSRPDS, "fares_Plati");
                ta = new SqlDataAdapter("SELECT * FROM [fares_Plati] WHERE [IDDocument]=" + iddocument.ToString(), sqlConnSubrep);

                ta.Fill(eSRPDS.fares_Plati);
                args.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("fares_Plati", bs));
            }
            if (args.ReportPath == "PlatiFacturiDetaliateSubreport")
            {
                Int64 iddocument = Convert.ToInt64(args.Parameters["identDocument"].Values[0]);

                bs = new BindingSource(eSRPDS, "fares_Plati");
                ta = new SqlDataAdapter("SELECT * FROM [fares_Plati] WHERE [IDDocument]=" + iddocument.ToString(), sqlConnSubrep);

                ta.Fill(eSRPDS.fares_Plati);
                args.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("fares_Plati", bs));
            }
            if (ta != null)
                ta.Dispose();
           
        }

        private void addPartenerB_Click(object sender, EventArgs e)
        {
            if (partenerCB.SelectedValue == null)
                return;
            furnizoriSelectatiBindingSource.Add(new FurnizoriArticoleSelectate(partenerCB.Text,
                Convert.ToInt64(partenerCB.SelectedValue)));
            parteneriRB.Checked = true;
        }

        private void delPart_Click(object sender, EventArgs e)
        {
            if (furnizoriSelectatiBindingSource.Count>0)
                furnizoriSelectatiBindingSource.RemoveCurrent();
        }

        private void addArt_Click(object sender, EventArgs e)
        {
            articoleSelectateBindingSource.Add(new FurnizoriArticoleSelectate(articolCB.Text,
                Convert.ToInt16(articolCB.SelectedValue)));
            articoleRB.Checked = true;
        }

        private void delArt_Click(object sender, EventArgs e)
        {
            articoleSelectateBindingSource.RemoveCurrent();
        }

        Boolean _blockUpdate = false;
        private void documenteCLB_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == e.CurrentValue || _blockUpdate)
                return;
            CheckedListBox clb = sender as CheckedListBox;
            //tipuriCLB.CheckedItems;
            _itemInfo ci = clb.Items[e.Index] as _itemInfo;
            for (int i = 0; i < tipuriCLB.Items.Count; i++)
                if (((_itemInfo)tipuriCLB.Items[i]).CodString.Contains(ci.CodString))
                {
                    tipuriCLB.SetItemChecked(i, e.NewValue == CheckState.Checked);
                }

        }

        private void tipuriCLB_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (documenteCLB.Items.Count == 0 || e.NewValue == e.CurrentValue)
                return;
            CheckedListBox clb = sender as CheckedListBox;
            _itemInfo ci = clb.Items[e.Index] as _itemInfo;
            if (((_itemInfo)tipuriCLB.Items[e.Index]).CodString.Contains("I"))
            {
                _blockUpdate = true;
                documenteCLB.SetItemChecked(0, true);
                _blockUpdate = false;
                return;
            }
            if (((_itemInfo)tipuriCLB.Items[e.Index]).CodString.Contains("O"))
            {
                _blockUpdate = true;
                documenteCLB.SetItemChecked(1, true);
                _blockUpdate = false;
                return ;
            }
        }

        
    }

    public class _itemInfo : Object
    {
        public String Nume = String.Empty;
        public Int32 Cod = 0;
        public String CodString = String.Empty;
        public _itemInfo(String _nume, Int32 _cod)
        {
            Nume = _nume;
            Cod = _cod;
        }
        public _itemInfo(String _nume, String _codS)
        {
            Nume = _nume;
            CodString = _codS;
        }
        public _itemInfo(String _nume, String _codS, Int32 _cod)
        {
            Nume = _nume;
            CodString = _codS;
            Cod = _cod;
        }

        override public String ToString()
        {
            return Nume;
        }

    }
    
}
